package com.ruoyi.project.cms.taskdelaycheck.controller;

import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.cms.task.domain.Assignment;
import com.ruoyi.project.cms.taskdelayask.domain.Delayapply;
import com.ruoyi.project.cms.taskdelayask.service.DelayapplyService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/cms/taskdelaycheck")
public class Delaycheck extends BaseController {
    private String prefix = "cms/taskdelaycheck";

    @Autowired
    private DelayapplyService delayapplyService;


    @GetMapping("/delaycheck")
    public String taskdelaycheck()
    {
        return prefix + "/delaycheck";
    }

    @RequiresPermissions("monitor:operlog:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Delayapply delayapply, String roleName)
    {
        startPage();
        List<Delayapply> list = delayapplyService.selectAll(delayapply,roleName);
        return getDataTable(list);

    }

    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        Delayapply delayapply = delayapplyService.selectOne(id);
        Assignment date = delayapplyService.findDate(id);
        Date endDate = date.getEndDate();
        mmap.put("owerDate",endDate);
        mmap.put("delayapply",  delayapply);
        return prefix + "/edit";
    }

    @PostMapping("/editSave")
    @ResponseBody
    public AjaxResult editSave(Delayapply delayapply)
    {
        Date date = new Date();
        System.out.println(date);
        delayapply.setCdate(date);
        int i = delayapplyService.updateDelay(delayapply);
        return toAjax(i);
    }
}
